﻿/*
 * Autore: Paolo Farina
 */

using System;
using System.Windows;
using System.Windows.Controls;
using RecipesManager.MainControls;

namespace RecipesManager
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class PageSwitcher : Window
    {
        IMyUserControls _currentPage = null;

        public PageSwitcher()
        {
            InitializeComponent();
            Switcher.PageSwitcher = this;
            Switcher.Switch(new MainMenu());
        }


        public void Navigate(UserControl nextPage)
        {
            if (nextPage is CategoryUserControl)
                Title = Properties.Resources.CategoriesManagerTitle;
            else if (nextPage is IngredientUserControl)
                Title = Properties.Resources.IngredientsManagerTitle;
            else if (nextPage is ShopUserControl)
                Title = Properties.Resources.ShopManagerTitle;
            else if (nextPage is MainMenu)
                Title = Properties.Resources.ProgramTitle;
            else if (nextPage is GuestUserControl)
                Title = Properties.Resources.GuestManagerTitle;
            else if (nextPage is RecipeUserControl)
                Title = Properties.Resources.RecipesManagerTitle;
            else if (nextPage is EventUserControl)
                Title = Properties.Resources.EventsManagerTitle;
            else if (nextPage is ShopListUserControl)
                Title = Properties.Resources.ShopListManagerTitle;
            //else if (............)
            Content = nextPage;
            _currentPage = (IMyUserControls) nextPage;
        }

        public void Navigate(UserControl nextPage, object state)
        {
            Content = nextPage;
            var s = nextPage as ISwitchable;

            if (s != null)
                s.UtilizeState(state);
            else
                throw new ArgumentException("NextPage is not ISwitchable! "
                                            + nextPage.Name);
        }

        private void Window_Closing_1(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = !_currentPage.Save_Context();
        }
    }
}